package com.jwsoft.manager.core.util;

import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.core.helper.ApiContainer;
import com.bifang.module.base.core.helper.ApiModel;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.eduSystemConfig.EduSystemConfigFuncQueryVO;
import com.jwsoft.manager.core.integration.EduSystemConfigIntegration;
import com.jwsoft.manager.core.integration.OperationCacheIntegration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
/**
 * 教育工具类
 * */
public class EduHelper {
    @Autowired
    public EduSystemConfigIntegration eduSystemConfigIntegration;
    @Autowired
    private ApiContainer apiContainer;
    @Autowired
    private CommonIntegration commonIntegration;
    @Autowired
    private OperationCacheIntegration operationCacheIntegration;
    public String thisAreaCode(){
        //获取当前部署行政区划
        CommonVO commonVO=new CommonVO();
        commonVO.setParamKey("area_code");
        String areaCode=commonIntegration.getValueByKey(commonVO);
        if(StringUtils.isBlank(areaCode)){
            throw new AppException("系统参数中当前部署行政区划不能为空");
        }

        return areaCode;
    }

    public ApiModel getEduFunc(String key, String areaCode){
        EduSystemConfigFuncQueryVO queryVO=new EduSystemConfigFuncQueryVO();
        queryVO.setAreaCode(areaCode);
        queryVO.setEduConfigKey(key);
        String funcCode=eduSystemConfigIntegration.getFuncCode(queryVO);
        ApiModel apiModel=apiContainer.get(funcCode);
        if(apiModel==null){
            throw new AppException(areaCode+"未找到处理"+key+"的个性化方法");
        }
        return apiModel;
    }
    public Integer thisYear(){
        //获取当前部署行政区划
        return operationCacheIntegration.getPeriodYear().getYear();
    }
    /**
     * 业务期校验
     * */
    public void checkOperation(EduOperationCacheQueryVO vo){
        eduSystemConfigIntegration.checkOperation(vo);
    }
    /**
     * 业务期校验
     * */
    public void checkOperation(String classify,String operating,String areaCode){
        if(StringUtils.isBlank(areaCode)){
            areaCode=thisAreaCode();
        }
        EduOperationCacheQueryVO vo=new EduOperationCacheQueryVO();
        vo.setAreaCode(areaCode);
        vo.setClassify(classify);
        vo.setOperating(operating);
        eduSystemConfigIntegration.checkOperation(vo);
    }
}
